package com.serviceImpl;

import java.util.Date;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import com.dao.manager.ConstructionMapper;
import com.pojo.Construction;
import com.service.ConstructionService;
import com.utils.UUIDUtils;

@Service
public class ConstructionServiceImp implements ConstructionService{

	@Resource
	private ConstructionMapper constructionMapper;
	@Override
	public int addConstructionInfo(Map<String, String> paramsMap) {
		try {
			String uuid = UUIDUtils.getUUID();
			Construction entity = new Construction();
			entity.setUuid(uuid);
			entity.setDeviceid(Integer.valueOf(paramsMap.get("deviceid")));
			entity.setProject(paramsMap.get("project"));
			entity.setBuilders(paramsMap.get("builders"));
			entity.setChecker(paramsMap.get("checker"));
			entity.setRating(paramsMap.get("rating"));
			entity.setCreatetime(new Date());
			System.out.println("entity:---》"+entity);
			constructionMapper.addConstructionInfo(entity);
			return 1;
		} catch (Exception e) {
			e.printStackTrace();
			return -1;
		}
	}
	@Override
	public int deleteConstructionInfo(Map<String, String> paramsMap) {
		try {
			return constructionMapper.deleteConstructionInfo(paramsMap);
		} catch (Exception e) {
			e.printStackTrace();
			return -2;
		}
	}
	@Override
	public int updateConstructionInfo(Map<String, String> paramsMap) {
		try {
			String uuid = paramsMap.get("uuid");
			Construction entity = new Construction();
			entity.setUuid(uuid);
			entity.setProject(paramsMap.get("project"));
			entity.setBuilders(paramsMap.get("builders"));
			entity.setChecker(paramsMap.get("checker"));
			entity.setRating(paramsMap.get("rating"));
			entity.setCreatetime(new Date());
			constructionMapper.updateConstructionInfo(entity);
			return 1;
		} catch (Exception e) {
			e.printStackTrace();
			return -1;
		}
	}
	@Override
	public List<Map<String, String>> getConstructionInfo(Map<String, String> paramsMap) {
		String page = paramsMap.get("page");
		if (page == null || "".equals(page)) {
			page = "1";
		}
		String num = paramsMap.get("num");
		if (num == null || "".equals(num)) {
			num = "10";
			paramsMap.put("num", num);
		}
		int start = (Integer.parseInt(page) - 1) * Integer.parseInt(num);
		paramsMap.put("start", start + "");
		return constructionMapper.getConstructionInfo(paramsMap);
	}
	@Override
	public List<Map<String, String>> getConstructionByUuid(Map<String, String> paramsMap) {
		return constructionMapper.getConstructionByUuid(paramsMap.get("id"));
	}

}
